package yogiro.dao;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.springframework.orm.ibatis.SqlMapClientTemplate;

import yogiro.to.CommentTO;
import yogiro.to.MapTO;
import yogiro.to.PictureTO;
import yogiro.to.RecommendTO;
import yogiro.to.TourInfoTO;
import yogiro.util.Utilities;

public class TourInfoDAO {
private SqlMapClientTemplate sqlMap;
	
	public TourInfoDAO(SqlMapClientTemplate sqlMap){
		this.sqlMap = sqlMap;
	}
	
	public Object insertTourInfo(TourInfoTO tio) throws Exception{
		return sqlMap.insert("insertTourInfo", tio);
	}
	
	public ArrayList<CommentTO> selectAllComment(int tourNo)throws SQLException{
		return (ArrayList<CommentTO>)sqlMap.queryForList("selectAllComment",tourNo);
	}
	
	public ArrayList<TourInfoTO> selectTourRecommend(String tourWriterType) throws SQLException{
		return (ArrayList<TourInfoTO>)sqlMap.queryForList("selectTourRecommend", tourWriterType);
	}
	
	public PictureTO selectTourRecommend2(int pictureGroup) throws SQLException{
		return (PictureTO)sqlMap.queryForObject("selectTourRecommend2", pictureGroup);
	}
	
	public ArrayList<PictureTO> selectTourRecommend3(int pictureGroup) throws SQLException{
		return (ArrayList<PictureTO>)sqlMap.queryForList("selectTourRecommend3", pictureGroup);
	}
	
	public Object insertMap(MapTO mto) throws Exception{
		return sqlMap.insert("insertMap", mto);
	}
	
	public Object pictureUp(PictureTO pto) throws SQLException{
		return sqlMap.insert("insertPicture", pto);
	}
	
	
	public int selectTotalContent() throws SQLException{
		return (Integer)sqlMap.queryForObject("selectTotalContent");
	}
	
	public ArrayList<TourInfoTO> selectTourListByPage(int page) throws SQLException{
		HashMap map = new HashMap();
		map.put("contentPerPage", Utilities.CONTENT_PER_PAGE);
		map.put("page", page);
		return (ArrayList<TourInfoTO>)sqlMap.queryForList("selectTourListByPage", map);
	}
	
	public MapTO selectMapByTourNo(int mapGroup) throws SQLException{
		return (MapTO)sqlMap.queryForObject("selectMapByTourNo", mapGroup);
	}

	public TourInfoTO selectContentBytourNO(int tourNo) throws SQLException{
		return (TourInfoTO)sqlMap.queryForObject("selectContentBytourNO", tourNo);
	}
	
	public int updateViewCount(int tourNo) throws SQLException{
		return sqlMap.update("updateViewCount", tourNo);
	}
	
	//추천수
	public int updateRecommend(int tourNo) throws SQLException{
		return sqlMap.update("updateRecommend", tourNo);
	}
	public int selectRecommend(HashMap map) throws SQLException{
		return (int)sqlMap.queryForObject("selectRecommend", map);
	}
	public Object insertRecommend(RecommendTO rto) throws SQLException{
		return sqlMap.insert("insertRecommend", rto);
	}
	
	public int updateContent(TourInfoTO tio) throws SQLException{
		return sqlMap.update("updateContent", tio);
	}
	
	public int updatePicture(PictureTO pto) throws SQLException{
		return sqlMap.update("updatePicture", pto);
	
	}
	public int updateMap(MapTO mto) throws SQLException{
		return sqlMap.update("updateMap", mto);
	}
	
	public int deleteContentByTourNO(int tourNo) throws SQLException{
		return sqlMap.delete("deleteContentByTourNO", tourNo);
	}
	
	public int deletePictureByTourNO(int pictureGroup) throws SQLException{
		return sqlMap.delete("deletePictureByTourNO", pictureGroup);
	}
	
	public int deleteMapByTourNO(int mapGroup) throws SQLException{
		return sqlMap.delete("deleteMapByTourNO", mapGroup);
	}
	
	public int deleteCommentByTourNO(int tourNo)throws SQLException{
		return sqlMap.delete("deleteCommentByTourNO", tourNo);
	}
	
}
